//
//  CardDetailViewController.m
//  DaDaBao
//
//  Created by admin on 15/8/19.
//  Copyright (c) 2015年 User. All rights reserved.
//

#import "CardDetailViewController.h"

@interface CardDetailViewController ()

@property (nonatomic, strong) NSString *cardIdString;

@property (nonatomic, strong) NSString *bankName;
@end

@implementation CardDetailViewController

- (id)initWithCardId:(NSString *)cardIdString andTheBankName:(NSString *)name
{
    self = [super init];
    if(self)
    {
        _cardIdString = cardIdString;
        _bankName = name;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor hexStringToColor:@"#ebebeb"];
    
    [self createUI];
}
-(void)createUI
{
    TopView *topView =[[TopView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 64.0f)];
    [topView setTitile:@"银行卡详情"];
    
    UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0.0f, 20.0f, 64.0f, 44.0f)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(buttonBackTapped:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:backBtn];
    
    [self.view addSubview:topView];
//  标题
    UILabel *successLab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 64.0f+30.0f, SCREEN_WIDTH, 100.0f)];
    successLab.text = @"绑定成功!";
    successLab.font = [UIFont boldSystemFontOfSize:20.0f];
    successLab.backgroundColor = [UIColor whiteColor];
    successLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:successLab];
//  银行卡
    UIView *bankView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, successLab.frame.size.height+successLab.frame.origin.y, SCREEN_WIDTH , 100.0f)];
    bankView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bankView];
    //    分割线
    for (int i=0; i<2; i++) {
        UILabel *sepLab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 99.9f*i, SCREEN_WIDTH, 0.5f)];
        sepLab.backgroundColor = [UIColor blackColor];
        [bankView addSubview:sepLab];
    }
//    logo
     UILabel *bankNameLab = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 25.0f, SCREEN_WIDTH-60.0f, 20.0f)];
     bankNameLab.font = [UIFont systemFontOfSize:20.0f];
     bankNameLab.textAlignment = NSTextAlignmentCenter;
     bankNameLab.text = _bankName;//需要赋值
     [bankView addSubview:bankNameLab];
    
    UILabel *cardNumLab = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, bankNameLab.frame.origin.y+bankNameLab.frame.size.height+15.0f, SCREEN_WIDTH-60.0f, 20.0f)];
    cardNumLab.textAlignment = NSTextAlignmentCenter;
    cardNumLab.textColor = [UIColor grayColor];
    cardNumLab.font = [UIFont systemFontOfSize:17.0f];
    //        需要请求赋值
    cardNumLab.text =     [self secureThePhoneNum:_cardIdString];
;
    [bankView addSubview:cardNumLab];


//  提示
    UILabel *detailLab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, bankView.frame.size.height+bankView.frame.origin.y, SCREEN_WIDTH, 100.0f)];
    detailLab.text = @"您已设置快捷卡，可放心进行充值、提现、投资";
    detailLab.font = [UIFont systemFontOfSize:14.0f];
    detailLab.textColor = [UIColor redColor];
    detailLab.backgroundColor = [UIColor whiteColor];
    detailLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:detailLab];

    // 完成按钮
    UIButton *completeBtn =  [UIButton buttonWithType:UIButtonTypeCustom];
    completeBtn.frame = CGRectMake(15.0f, detailLab.frame.origin.y+detailLab.frame.size.height+25.0f, SCREEN_WIDTH-30.0f, 35.0f*HSCALE);
    [completeBtn setBackgroundColor:[UIColor hexStringToColor:RED_COLOR_VALUE]];
    [completeBtn setTitle:@"完成" forState:UIControlStateNormal];
    completeBtn.layer.cornerRadius = 5.0f;
    [completeBtn addTarget:self action:@selector(buttonCompleteTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:completeBtn];
    

}
#pragma mark- 完成按钮方法
-(void)buttonCompleteTapped:(id)sender
{
    NSArray *listArray = self.navigationController.viewControllers;
    
    [self.navigationController popToViewController:[listArray objectAtIndex:3] animated:TRUE];
}
//给银行卡加*号
-(NSString *)secureThePhoneNum:(NSString *)phoneNum
{
    if (phoneNum.length==19) {
        return [phoneNum stringByReplacingCharactersInRange:NSMakeRange(3, phoneNum.length-7) withString:@"************"];
    }
    else
    {
        return [phoneNum stringByReplacingCharactersInRange:NSMakeRange(3, phoneNum.length-7) withString:@"*********"];
    }
    
}

#pragma mark-返回按钮方法
-(void)buttonBackTapped:(id)sender
{
    [self.navigationController popViewControllerAnimated:TRUE];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
